#!/usr/bin/env bash
set -euo pipefail

export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-linux-musl-gcc

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "${SCRIPT_DIR}"

TARGET_TRIPLE="aarch64-unknown-linux-musl"

echo "Building sbox for ${TARGET_TRIPLE}..."
cargo build --release --target "${TARGET_TRIPLE}" "$@"

cp "target/${TARGET_TRIPLE}/release/sbox" "${STARRY_BUILD}/"
echo "Build complete. Artifact copied to ${STARRY_BUILD}/sbox"

cd "${STARRY_BUILD}"
git add sbox
git commit -m "Build sbox for ${TARGET_TRIPLE}"
git push
